package com.sright.bcard.common.service.share.dto.pager;

import java.io.Serializable;
import java.util.List;

/**
 * @author pro
 * @version V1.0
 * @since 2019-02-13 17:41
 */
public class Pager<T> implements Serializable {

    private static final long serialVersionUID = 1038184723205915125L;

    /**
     * 当前页
     */
    private int pageNo = 1;

    /**
     * 页大小
     */
    private int pageSize = 10;

    /**
     * 总条数
     */
    private int total;

    /**
     * 总页数
     */
    private int totalPage;

    /**
     * 返回数据
     */
    protected List<T> list;

    public Pager(int pageNo, int pageSize, int total, List<T> list) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        if(pageSize<=0){
            this.pageSize = 20;
        }else{
            this.pageSize = pageSize;
        }
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    //重第一页开始
    public int getTotalPage() {
        return this.total%this.pageSize == 0 ? this.total/this.pageSize : (this.total/this.pageSize)+1;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public static void main(String[] args){
//        Pager<Long> pager = new Pager<>(1,10,32);
//        System.out.println(pager.getTotalPage());
    }

}
